﻿	<?php
	$get_title = $_REQUEST['title'];
	$get_content = $_REQUEST['content'];
	$get_author = $_REQUEST['author'];

	if($get_title == "") {
		$value_title = false;
	} else {
		$value_title = true;
	}
	
	if($get_content == "") {
		$value_content = false;
	} else {
		$value_content = true;
	}

	if($get_author == "") {
		$value_author = false;
	} else {
		$value_author = true;
	}	
	
	if($value_title == true && $value_content == true && $value_author == true) {
		include("config.php");
		$db	= mysql_connect(DB_HOST, DB_USER, DB_PASS);
		mysql_select_db(DB_NAME, $db);

		$select_id = mysql_query("SELECT id FROM ms_posts", $db);
		$num_id = mysql_num_rows($select_id);
		$num_id ++;

		$sql_new_post = ("INSERT INTO ms_posts 
		(id, post_name, post_content, post_author)
		VALUES ('".$num_id."', '".$get_title."', '".$get_content."', '".$get_author."')");
	
		mysql_query("SET NAMES 'utf8' COLLATE 'utf8_general_ci'", $db);
		$result_query = mysql_query($sql_new_post, $db);

		if($result_query) {
			echo "نوشته شما با نام ".$get_title. " در پايگاه‌داده ذخيره شد.";
		} else {
			die("Error:".mysql_error() );
		}
	} else {
		echo "خطا! لطفا فرم را کامل پر کنید.";
	}
?>